﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using EFEntity;
using ISerives;
using Microsoft.EntityFrameworkCore;
using Model;

namespace Serives
{
    public class config_public_charSerives : Iconfig_public_charSerives
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;

        public config_public_charSerives(MyDbContext myDbContext,IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> Add(Econfig_public_char ecpc)
        {
            await myDbContext.Cpc.AddAsync(ecpc);
            return  myDbContext.SaveChanges();
        }

        public async Task<int> Del(int id)
        {
            myDbContext.Remove(myDbContext.Cpc.Where(e => e.pbc_id == id).FirstOrDefault());
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<List<config_public_char>> Select()
        {
            List<config_public_char> list = new List<config_public_char>();
         await  Task.Run(() =>
            {
               
                List<Econfig_public_char> list2 = myDbContext.Cpc.ToList();
                list = mapper.Map<List<config_public_char>>(list2);
            });
            return list;
        }

        public async Task<List<config_public_char>> SelectShow(string name)
        {
            List<config_public_char> list = new List<config_public_char>();
            await Task.Run(() =>
            {
                List<Econfig_public_char> list2 = myDbContext.Cpc.Where(e => e.attribute_kind == name).ToList();
                list = mapper.Map<List<config_public_char>>(list2);
            });
            return list;
        }

        public Task<int> Upd(Econfig_public_char ecpc)
        {
            throw new NotImplementedException();
        }
    }
}
